﻿using editor.cfg;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace editor
{
    /// <summary>
    /// MainWindow.xaml 的交互逻辑
    /// </summary>
    public partial class MainWindow : Window
    {

        public MainWindow()
        {
            InitializeComponent();

            LoadConfig();
        }

        private void LoadConfig()
        {
            if (cfg.Manager.Ins.Load())
            {
                configs.DataContext = Manager.Ins.Defines.EditorConfigs;
                configs.SelectedIndex = 0;
            }
        }

        private void SaveAll(object sender, RoutedEventArgs e)
        {
            foreach (var c in Manager.Ins.Defines.EditorConfigs)
            {
                c.SaveAll();
            }
        }

        private void ReloadConfig(object sender, RoutedEventArgs e)
        {
            LoadConfig();
        }

        private void SetCfgXmlPath(object sender, RoutedEventArgs e)
        {
            cfg.Manager.Ins.ChooseCfgXmlFile();
        }


        /**
         *  强制 重新保存所有文件, 哪怕它没有改动过
         *  适合用于某些配置表新增或者删除了字段,强制重新保存,可以让配置更到最新
         */
        private void ForceSaveAll(object sender, RoutedEventArgs e)
        {
            foreach (var c in Manager.Ins.Defines.EditorConfigs)
            {
                c.ForceSaveAll();
            }
        }

    }
}
